package com.tianchi.lexiang.bean;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class DrawPoint {
	private static final String TAG = "LeXiang";
	
	public int whichDraw;
	public int x;
	public int y;
	private boolean isUsing;

	private DrawPoint(){}
	
	private static final int CACHE_SIZE = 13;
	private static List<DrawPoint> cache = new ArrayList<DrawPoint>(CACHE_SIZE);

	public static DrawPoint getDrawPoint() {
		int size = cache.size();
		for (int i = 0;i< size; i++) {
			DrawPoint point = cache.get(i);
			if (!point.isUsing) {
				point.isUsing = true;
//				log("return a point in cache,i==>"+i);
				return point;
			}
		}
		DrawPoint newPoint = new DrawPoint();
		newPoint.isUsing = true;
//		log("build a new DrawPoint,add to cache");
		cache.add(newPoint);
		return newPoint;
	}

	public static boolean resetCacheDrawPointUseingState() {
		for (DrawPoint point : cache) {
			point.isUsing = false;
		}
		log("reset isUsing in cache");
		return true;
	}

	public static void releaseCache() {
		cache.clear();
	}

	@Override
	public String toString() {
		return "DrawPoint [whichDraw=" + whichDraw + ", x=" + x + ", y=" + y
				+ "]";
	}
	
	private static void log(String msg){
		Log.d(TAG, "[DrawPoint]"+msg);
	}
}
